extends Button

var _pressed = false
var _offsetX = 7
onready var _block = get_node("box/block")
onready var _bar = get_node("box/bar")
onready var _sizeW = _bar.rect_size.x

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

func _on_progressBar_gui_input(event):
	if event is InputEventMouseButton:
		if event.pressed:
			setValue((event.position.x-_offsetX) / _sizeW)
			_pressed = true
		elif !event.pressed:
			_pressed = false
	elif event is InputEventMouseMotion && _pressed:
		setValue((event.position.x-_offsetX) / _sizeW)
		pass
	pass # Replace with function body.

func setValue(v : float):
	if v <= 0.0:
		v = 0
	if v >= 1.0:
		v = 1.0
	_block.position.x = _sizeW * v
	_bar.value = v
	pass
